<template>
    <zh-form :span="24" :labelCol="labelCol" :wrapperCol="wrapperCol"  ref="rolePageFrom" :model="form" :rules="rules">
        <zh-input prop="roleName" :required="true" label="角色名称" placeholder="请输入角色名称" v-model="form.roleName"></zh-input>
        <zh-input prop="roleType" type="select" label="角色类型"  placeholder="单选" allowClear  :options="dictData.roleType" v-model="form.roleType" ></zh-input>
        <zh-input prop="status" type="select"  label="状态"  placeholder="单选" allowClear  :options="statusData" v-model="form.status" ></zh-input>  
        <zh-input prop="remarks" type="textarea" :rows="4" label="备注"    v-model="form.remarks" ></zh-input>  
        <zh-input :style="{display:'none'}" prop="roleId" label="角色id"  v-model="form.roleId"></zh-input>     
        <zh-input :style="{display:'none'}" prop="parentId" label="上级角色id"  v-model="form.parentId"></zh-input>     
    </zh-form>
</template>

<script>
import { getBatchDict } from "@/services/system/api"
export default {
  data () {
    return {
      dictData: {},
      form: {roleName:undefined,roleType:undefined,status:undefined,remarks:undefined,roleId:undefined,parentId:undefined},
      statusData:[{dictKey:'1',dictValue:'启用'},{dictKey:'0',dictValue:'禁用'}],
      labelCol:{ 
        xs: { span: 24 },
        sm: { span: 6 },
        md: { span: 5 },
        lg: { span: 5 },
        xl: { span: 5 },
        xxl: { span: 5 }},
      wrapperCol:{
        xs: { span: 24 },
        sm: { span: 18 },
        md: { span: 19 },
        lg: { span: 19 },
        xl: { span: 19 },
        xxl: { span: 19 }
      },
      rules: {
        roleName:[
            { required: true, message: '请输入角色名' }
        ],
        status:[
            { required: true, message: '请输入状态' }
        ]
      }

    }
  },
  props: {
    roleInfo: {
      type: Object,
      default: () => {},
      required: false
    }
  },
  created () {
    // 数据初始化
    const params = {}
    params.dictFields = 'roleType'
    this.$http.post(getBatchDict,params).then(res => {
      this.dictData = res.result
    })
    let form=Object.assign(this.form,this.roleInfo)
    this.from =form
  },
  methods: {
    checkForm(){
        let flag=true
        this.$refs.rolePageFrom.validate(valid => {
            if(valid){
                flag=true
            }else{
                flag=false
            }
        });
        return flag
    }
  }
}
</script>
